package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.domain.CommonResult;
import com.atguigu.springcloud.domain.Order;
import com.atguigu.springcloud.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class OrderController {
	
	@Autowired
	private OrderService orderService;
	
	@PostMapping("/order")
	public CommonResult<Order> insertOrder(Order o){
		int i = orderService.insertSelective(o);
		if (i == 0) {
			return new CommonResult<>(500,"出错了o(╥﹏╥)o",new Order());
		} else {
			return new CommonResult<>(200,"下单成功",o);
		}
	}
	
	@GetMapping("/order/{id}")
	public CommonResult<Order> getOrderByID(@PathVariable("id")Long id){
		Order order = orderService.selectByPrimaryKey(id);
		if (order == null) {
			return new CommonResult<>(404,"找不到该订单",order);
		} else {
			return new CommonResult<>(200,"查询成功",order);
		}
		
	}



}
